<?php

/*
Zoo Management Simulation
This file provides editing functionality allowing the user to edit an entry in the database.
The layout is the same as the addCage file and already has values selected when it is loaded
*/

include("dbconnect.php");
$cageid = $_REQUEST['cageid'];

$sql = "SELECT * FROM enclosure WHERE enclosureId=".$cageid;

foreach($dbh->query($sql) as $row)
	{
		$name = $row[1];
		$size = $row[2];
		$typeid = $row[3];
		$exhibitname = $row[4];
		$exhibitdesc = $row[5];
		$numberofentries = $row[6];
		$animaldetector = $row[9];
		$humandetector = $row[10];
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Cage</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Edit Cage</h1>

<form id="editCageForm" name="editCageForm" method="post" enctype="multipart/form-data" action="editCageEntry.php">

<table id="zootable" width="100%" border="1">
  <tr>
    <td id="tableheader"><label for="name">Name</label></td>
    <td id="tableheader"><label for="size">Size</label></td>
    <td id="tableheader"><label for="type">Type</label></td>
    <td id="tableheader"><label for="numentry">Number of entries</label></td>
    <td id="tableheader"><label for="exhibitname">Exhibit Name</label></td>
    <td id="tableheader"><label for="exhibitdesc">Exhibit Description</label></td>
    <td id="tableheader"><label for="humandetector">Human Detector</label></td>
    <td id="tableheader"><label for="animaldetector">Animal Detector</label></td>
  </tr>
  
  <tr>
  <?php
    echo '<td><input type="range" name="name" id="name" value="'.$name.'" /></td>';
    echo '<td><input type="number" name="size" id="size" value="'.$size.'" /></td>';
    echo '<td><select name="type" id="type">';
	
    echo '<option value="1"';
	if ($typeid == 1) {echo "selected='selected'";}
	echo '>Open Enclosure</option>';
	
    echo '<option value="2"';
	if ($typeid == 2) {echo "selected='selected'";}
	echo '>Glass Enclosure</option>';
	
    echo '<option value="3"';
	if ($typeid == 3) {echo "selected='selected'";}
	echo '>Bar Enclosure</option>';
	
    echo '<option value="4"';
	if ($typeid == 4) {echo "selected='selected'";}
	echo '>Wire Enclosure</option>';
	
	echo '</select></td>';
	
	echo '<td><select name="numentry" id="numentry">';
	
    echo '<option value="1"';
	if ($numberofentries == 1) {echo "selected='selected'";}
	echo '>1</option>';
	
    echo '<option value="2"';
	if ($numberofentries == 2) {echo "selected='selected'";}
	echo '>2</option>';
	
	
    echo '<option value="3"';
	if ($numberofentries == 3) {echo "selected='selected'";}
	echo '>3</option>';
	
	echo '</select></td>';   

    echo '<td><input type="text" name="exhibitname" id="exhibitname" value="'.$exhibitname.'" /></td>';
    echo '<td><input type="text" name="exhibitdesc" id="exhibitdesc" value="'.$exhibitdesc.'" /></td>';
	
	echo '<td><select name="animaldetector" id="animaldetector">';
	
    echo '<option value="1"';
	if ($animaldetector == 1) {echo "selected='selected'";}
	echo '>Animal Inside</option>';
	
    echo '<option value="0"';
	if ($animaldetector == 0) {echo "selected='selected'";}
	echo '>No Animal Inside</option>';
		
	echo '</select></td>'; 
	
	echo '<td><select name="humandetector" id="humandetector">';
	
    echo '<option value="1"';
	if ($humandetector == 1) {echo "selected='selected'";}
	echo '>Human Inside</option>';
	
    echo '<option value="0"';
	if ($humandetector == 0) {echo "selected='selected'";}
	echo '>No Human Inside</option>';
		
	echo '</select></td>'; 

	echo "<input type='hidden' name='cageid' value='".$cageid . "' />";
  $dbh = null;?>
  </tr>
</table>
<br />
<input type="submit" name="submit" id="submit" value="Edit Cage" />
<input type="submit" name="submit" id="submit" value="Return to Administator page" />
</form>
</body>
</html>